﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace lcmyjobs.Web.users
{
    public partial class mySearch : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Title = string.Format("个人管理中心—职位搜索：系统智能搜索职位   {0}", Application["webname"].ToString());
                if (Session["user_id"] != null)
                {
                    int id = int.Parse(Session["user_id"].ToString());
                    this.lblName.Text = Session["user_name"].ToString();
                    lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
                    DropDownList1.DataSource = bub.GetUserJobs(id).Tables[0];
                    DropDownList1.DataTextField = "job_name";
                    DropDownList1.DataValueField = "jobs_id";
                    DropDownList1.DataBind();
                }
                else
                {
                    Response.Redirect("userlogin.html");
                }
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (Session["user_id"] != null)
            {
                StringBuilder url = new StringBuilder("JobList.html");
                url.Append(GetStr());
                Response.Redirect(url.ToString());
            }
            else
            {
                Response.Redirect("userlogin.html");
            }

        }
        private string GetStr()
        {

            int id = int.Parse(Session["user_id"].ToString());
            lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
            DataSet ds = bub.GetUserJob(id);
            StringBuilder str = new StringBuilder("?");
            int salary = 0;
            string area = "";
            string trade = "";
            if (ds.Tables[0].Rows.Count > 0)
            {
                salary = int.Parse(ds.Tables[0].Rows[0][2].ToString());

                if (salary > 0)
                {
                    if (salary < 1500)
                    {
                        salary = 1;
                    }
                    if (salary > 1500 && salary < 2000)
                    {
                        salary = 2;
                    }
                    if (salary > 2000 && salary < 3000)
                    {
                        salary = 3;
                    }
                    if (salary > 3000 && salary < 5000)
                    {
                        salary = 4;
                    }
                    if (salary > 5000)
                    {
                        salary = 5;
                    }
                }


            }
            if (ds.Tables[1].Rows.Count > 0)
            {
                area = "";
                for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                {
                    //string[] t_area = ds.Tables[1].Rows[i][1].ToString().Split('&bull;');
                    area += ds.Tables[1].Rows[i][1].ToString() + ",";
                    //area += t_area[0] + ",";
                }
                area = area.Substring(0, area.Length - 1);
            }
            if (ds.Tables[2].Rows.Count > 0)
            {
                trade = "";
                for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                {
                    trade += ds.Tables[2].Rows[i][1].ToString() + ",";
                }
                trade = trade.Substring(0, trade.Length - 1);
            }
            int type = 0;
            string jobs = DropDownList1.SelectedValue;
            jobs = "0";//期望职位不列为智能搜索条件

            int edu = 1;
            int exp = 1;
            string major = "";
            int lan = 1;
            int level = 0;
            string rtime = "0";
            string keywords = "";
            
            if (ds.Tables[4].Rows.Count > 0)
            {
                major = ds.Tables[4].Rows[0]["major_name"].ToString();
            }
            str.Append("workerclass=" + type);
            str.Append("&jobsname=" + jobs);
            str.Append("&areaname=" + area);
            //str.Append("&tradename=" + trade);
            str.Append("&salary=" + salary);
            str.Append("&edu=" + edu);
            str.Append("&exp=" + exp);
            str.Append("&majorname=" + major);
            str.Append("&lan=" + lan);
            str.Append("&level=" + level);
            str.Append("&releasetime=" + rtime);
            str.Append("&key_words=" + keywords);
            return str.ToString();

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("user_search.html");
        }
    }
}